package com.lucas.rpc.framework.handler;

import com.lucas.rpc.framework.entity.RpcRequest;
import com.lucas.rpc.framework.server.multiversion.LocalRegister;

import java.io.ObjectInputStream;
import java.lang.reflect.Method;

/**
 * @author: LiuCheng
 * @description:
 * @date: 2023-12-04 16:05
 **/
public class RpcRequestHandler {


    public Object handle(RpcRequest rpcRequest) {
        String interfaceName = rpcRequest.getInterfaceName();

        String version = rpcRequest.getVersion();

        Class implClass = LocalRegister.getImplClass(interfaceName, version);

        Method method = null;
        try {
            method = implClass.getMethod(rpcRequest.getMethodName(), rpcRequest.getParametersType());
            Object result = method.invoke(implClass.newInstance(), rpcRequest.getParameters());
            return result;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }



    }
}
